//============================================================================
// Name        : erase_effect.cpp
// Author      : dfoelber
//============================================================================

// INCLUDES //
#include "effect/erase_effect.h"
#include <stdlib.h>
//////////////

/**
* Constructor
* 
* @param owner The owner to this effect
**/
EraseEffect::EraseEffect(RegionEffectOwner* owner) :
	PuzzleEffect(owner)
{
}

/**
* Virtual destructor
**/
EraseEffect::~EraseEffect()
{
}

/**
* Notifies the effect to start.
* 
* Overridden from RegionEffect.
**/
void EraseEffect::OnStart()
{
	vector<Object*> objects = GetOwner()->GetObjects();
	
	vector<int> possibleIndexes;
	for( int i = 0; i < (int)objects.size(); i++ )
	{
		if( !GetOwner()->IsObjectActiveOrSimilar(objects[i]) )
			possibleIndexes.push_back(i);
	}
	
	if( (int)possibleIndexes.size() > 0 )
	{
		int index = rand() % (int)possibleIndexes.size();
		
		GetOwner()->RemoveObject(objects[index]);
	}
	else
	{
		GetOwner()->EffectDone();
	}
}

/**
* Notifies the effect that the finish state of the puzzle region is finished.
* 
* Overridden from PuzzleEffect.
**/
void EraseEffect::OnFinishCompleted()
{
	GetOwner()->EffectDone();
}

/**
* Asks the effect if it wants to freeze the active object and its association list.
* 
* Overridden from RegionEffect.
* 
* @return If the active object and association are to be frozen
**/
bool EraseEffect::FreezeActiveAndSimilar()
{
	return true;
}

/**
* Input that can be used by the effect.
* 
* @param event The event
* @return If the event was consumed
**/
bool EraseEffect::Input( SDL_Event event )
{
	return false;
}
